define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'video.video/index' + location.search,
                    add_url: 'video.video/add',
                    edit_url: 'video.video/edit',
                    del_url: 'video.video/del',
                    multi_url: 'video.video/multi',
                    import_url: 'video.video/import',
                    table: 'video',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'), operate: false},
                        {field: 'title', title: __('Title'), operate: 'LIKE'},
                        {field: 'des', title: __('Des'), operate: 'LIKE'},
                        {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'videocategory.name', title: __('Video_category_id'), operate: false},
                        {field: 'video_category_id', title: __('Video_category_id'), visible:false,searchList:$.getJSON('video/category/list')},
                        {field: 'price', title: __('Price'), operate: false},
                        {field: 'read_num', title: __('Read_num'), operate: false},
                        // {field: 'is_del', title: __('Is_del')},
                        {field: 'is_hot', title: __('精选'), formatter: Table.api.formatter.status, searchList: {1: __('是'), 0: __('否')}},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        // {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        {field: 'operate', title: __('Operate'), table: table,
                            buttons:[
                                {
                                    name:"catalogue",
                                    refresh:true,
                                    text:"视频目录",
                                    title:"视频目录",
                                    icon:"",
                                    classname:"btn btn-xs btn-info btn-dialog",
                                    url:"video/catalogue/index?video_id={ids}",
                                    extend: 'data-area=\'["60%","50%"]\'',
                                },
                            ],
                            events:Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
